import 'package:flutter/material.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:provider/provider.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBColor/YBColor.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBTextStyle/YBTextStyle.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBJsonToModel/YBMapMiShuModel/YBMapMiShuModel.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBJsonToModel/YBMapMiShuModel/YBMapMiShuSubModel.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBModule/YBHomePage/YBMapMiShuPage/YBMapMiShuProvider/YBMapMiShuDiTuProvider.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBModule/YBHomePage/YBMapMiShuPage/YBMapMiShuSubPage/YBMapBanLiShuWuSubPage.dart';

class YBMapBanLiShiWuPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
       child: Scaffold(
         appBar: AppBar(
            elevation: 0,
            title: Text(
              '选择办理事务',
            ),
         ),
         body: Column(
           children: [
             Expanded(
               child: ChangeNotifierProvider(
                   create: (context) => YBMapMiShuBanliShiWuProvodier()..getMapLabel("gscs_group,zscq_group,zzbl_group", ""),

                    child: Consumer<YBMapMiShuBanliShiWuProvodier>(
                       builder: (context,dataList,child){
                         print("object--${dataList.mishuShiWuList}-");

                         List miShuModelList = List();

                         for(YBMapMiShuModel miShuModel in dataList.mishuShiWuList){
                            miShuModelList.add(miShuModel);
                            for(YBMapMiShuSubModel subModel in miShuModel.children){
                              miShuModelList.add(subModel);
                            }
                         }

                         return StaggeredGridView.countBuilder(
                             crossAxisCount: 3,
                             crossAxisSpacing: 10,
                             itemCount: dataList.mishuShiWuList.length,
                             mainAxisSpacing: 10,
                             itemBuilder: (context,index){
                               var indexList = miShuModelList[index];
                               if (indexList is YBMapMiShuModel) {
                                 YBMapMiShuModel miShuModel = miShuModelList[index];
                                 return YBMapBanLiShiWuSubPage(
                                   banLiShiwuContentStr: miShuModel.name,);
                               }else {
                                 YBMapMiShuSubModel miShuModel = miShuModelList[index];
                                 return YBMapBanLiShiWuSubPage(
                                   banLiShiwuContentStr: miShuModel.name,);
                               }
                             },
                             staggeredTileBuilder: (int index){
                               var indexList = miShuModelList[index];
                               if (indexList is YBMapMiShuModel) {
                                 return StaggeredTile.count(1, 0.5);
                               }else {
                                 return StaggeredTile.count(3, 0.5);
                               }
                             }
                         );
                       }
                   ),
               ),
             ),
             Container(
               height: 60,
               child: Padding(
                 padding: EdgeInsets.only(left: 20,right: 20),
                 child: Row(
                   mainAxisAlignment: MainAxisAlignment.spaceBetween,
                   crossAxisAlignment: CrossAxisAlignment.center,
                   children: [
                     Expanded(
                       flex: 1,
                       child: Container(
                         height: 44,
                         child: OutlineButton(
                           shape: RoundedRectangleBorder(
                             borderRadius: BorderRadius.all(Radius.circular(8.0)),

                           ),
                           child: Text('清空',style: YBTextStyle.TextStyle64646416,),
                           onPressed: () async {

                           },
                         ),
                       ),
                     ),
                     Container(
                       width: 20,
                     ),
                     Expanded(
                       flex: 2,
                       child: Container(
                         height: 44,
                         child: RawMaterialButton(
                           shape: RoundedRectangleBorder(
                             borderRadius: BorderRadius.all(Radius.circular(4.0)),

                           ),
                           fillColor: YBColor.commonThemeColor,
                           child: Text('选好了',style: YBTextStyle.TextStyleFFFFFF16Medium,),
                           onPressed: () async {

                           },
                         ),
                       ),
                     ),
                   ],
                 ),
               ),
             ),
           ],
         ),
       ),
    );
  }
}
